RateLimiter.constructor   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 38

Duplication

Lines 38
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 38
loc 38
rs 8.8571

9 Functions

Rating   Name   Duplication   Size   Complexity  
A RateLimiter.timeLeft 7 7 1
A ratelimiter.js ➔ RateLimiter 3 3 1
A RateLimiter.isActive 3 3 1
A RateLimiter.call 9 9 3
A RateLimiter.callsLeft 3 3 1
A RateLimiter.timeLeft 3 3 1
A RateLimiter.isActive 7 7 1
A RateLimiter.callsLeft 7 7 1
A RateLimiter.call 11 11 1
1 View Code Duplication
"use strict";
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
Object.defineProperty(exports, "__esModule", { value: true });
3
var RateLimiter = /** @class */ (function () {
4
    function RateLimiter(rateLimits) {
5
        this.rateLimits = rateLimits;
6
    }
7
    RateLimiter.prototype.call = function (callback) {
8
        this.rateLimits.forEach(function (rateLimit) {
9
            if (!rateLimit.isActive()) {
10
                rateLimit.startTimer();
11
            }
12
            if (rateLimit.getCallsLeft() > 0) {
13
                rateLimit.decrementCall();
14
                callback();
15
            }
16
        });
17
    };
18
    RateLimiter.prototype.isActive = function () {
19
        var active = [];
20
        this.rateLimits.forEach(function (rateLimit) {
21
            active.push(rateLimit.isActive());
22
        });
23
        return active;
24
    };
25
    RateLimiter.prototype.callsLeft = function () {
26
        var active = [];
27
        this.rateLimits.forEach(function (rateLimit) {
28
            active.push(rateLimit.getCallsLeft());
29
        });
30
        return active;
31
    };
32
    RateLimiter.prototype.timeLeft = function () {
33
        var active = [];
34
        this.rateLimits.forEach(function (rateLimit) {
35
            active.push(rateLimit.getTimeLeft());
36
        });
37
        return active;
38
    };
39
    return RateLimiter;
40
}());
41
exports.RateLimiter = RateLimiter;
42
//# sourceMappingURL=ratelimiter.js.map